| Conditions | 1 |
| Paths | 1 |
| Total Lines | 128 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var assert = require('chai').assert, |
||
| 4 | describe('AtomEntry', function(){ |
||
| 5 | |||
| 6 | var json = { |
||
| 7 | authors: [ |
||
| 8 | { |
||
| 9 | name: 'author', |
||
| 10 | email: '[email protected]' |
||
| 11 | } |
||
| 12 | ], |
||
| 13 | contributors: [ |
||
| 14 | { |
||
| 15 | name: 'contributor', |
||
| 16 | email: '[email protected]' |
||
| 17 | } |
||
| 18 | ], |
||
| 19 | categories: [ |
||
| 20 | { |
||
| 21 | scheme: 'scheme', |
||
| 22 | term: 'term', |
||
| 23 | label: 'label' |
||
| 24 | } |
||
| 25 | ], |
||
| 26 | generator: { |
||
| 27 | uri: 'uri', |
||
| 28 | version: 'version', |
||
| 29 | value: 'value' |
||
| 30 | }, |
||
| 31 | icon: 'icon', |
||
| 32 | id: 'id', |
||
| 33 | links: { |
||
| 34 | rel: { |
||
| 35 | href: 'href' |
||
| 36 | } |
||
| 37 | }, |
||
| 38 | logo: 'logo', |
||
| 39 | rights: 'rights', |
||
| 40 | subtitle: 'subtitle', |
||
| 41 | title: 'title', |
||
| 42 | updated: 123456789, |
||
| 43 | content: { |
||
| 44 | gedcomx: { |
||
| 45 | description: '#root' |
||
| 46 | } |
||
| 47 | }, |
||
| 48 | confidence: 4, |
||
| 49 | published: 123456780, |
||
| 50 | source: { |
||
| 51 | logo: 'logo', |
||
| 52 | rights: 'rights', |
||
| 53 | subtitle: 'subtitle' |
||
| 54 | }, |
||
| 55 | summary: 'summary', |
||
| 56 | score: 122.32 |
||
| 57 | }; |
||
| 58 | |||
| 59 | it('Create plain', function(){ |
||
| 60 | assert.instanceOf(new GedcomX.AtomEntry(), GedcomX.AtomEntry, 'An instance of AtomEntry is not returned when calling the constructor with new.'); |
||
| 61 | assert.instanceOf(GedcomX.AtomEntry(), GedcomX.AtomEntry, 'An instance of AtomEntry is not returned when calling the constructor without new.'); |
||
| 62 | }); |
||
| 63 | |||
| 64 | it('Create with JSON', function(){ |
||
| 65 | tests(GedcomX.AtomEntry(json)); |
||
| 66 | }); |
||
| 67 | |||
| 68 | it('Build', function(){ |
||
| 69 | tests(GedcomX.AtomEntry() |
||
| 70 | .addAuthor( |
||
| 71 | GedcomX.AtomPerson() |
||
| 72 | .setName('author') |
||
| 73 | .setEmail('[email protected]') |
||
| 74 | ) |
||
| 75 | .addContributor( |
||
| 76 | GedcomX.AtomPerson() |
||
| 77 | .setName('contributor') |
||
| 78 | .setEmail('[email protected]') |
||
| 79 | ) |
||
| 80 | .addCategory( |
||
| 81 | GedcomX.AtomCategory() |
||
| 82 | .setScheme('scheme') |
||
| 83 | .setTerm('term') |
||
| 84 | .setLabel('label') |
||
| 85 | ) |
||
| 86 | .setGenerator( |
||
| 87 | GedcomX.AtomGenerator() |
||
| 88 | .setUri('uri') |
||
| 89 | .setVersion('version') |
||
| 90 | .setValue('value') |
||
| 91 | ) |
||
| 92 | .setIcon('icon') |
||
| 93 | .setId('id') |
||
| 94 | .addLink( |
||
| 95 | GedcomX.Link() |
||
| 96 | .setRel('rel') |
||
| 97 | .setHref('href') |
||
| 98 | ) |
||
| 99 | .setLogo('logo') |
||
| 100 | .setRights('rights') |
||
| 101 | .setSubtitle('subtitle') |
||
| 102 | .setTitle('title') |
||
| 103 | .setUpdated(123456789) |
||
| 104 | .setConfidence(4) |
||
| 105 | .setPublished(123456780) |
||
| 106 | .setSummary('summary') |
||
| 107 | .setScore(122.32) |
||
| 108 | .setContent({ |
||
| 109 | gedcomx: { |
||
| 110 | description: '#root' |
||
| 111 | } |
||
| 112 | }) |
||
| 113 | .setSource({ |
||
| 114 | logo: 'logo', |
||
| 115 | rights: 'rights', |
||
| 116 | subtitle: 'subtitle' |
||
| 117 | }) |
||
| 118 | ); |
||
| 119 | }); |
||
| 120 | |||
| 121 | it('toJSON', function(){ |
||
| 122 | assert.deepEqual(GedcomX.AtomEntry(json).toJSON(), json); |
||
| 123 | }); |
||
| 124 | |||
| 125 | it('constructor does not copy instances', function(){ |
||
| 126 | var obj1 = GedcomX.AtomEntry(); |
||
| 127 | var obj2 = GedcomX.AtomEntry(obj1); |
||
| 128 | assert.strictEqual(obj1, obj2); |
||
| 129 | }); |
||
| 130 | |||
| 131 | }); |
||
| 132 | |||
| 176 | } |